package com.cumt.threeway.activity;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.TextView;

import com.cumt.threeway.R;

/**
 * Created by 胡晶晶 on 2016/5/25.
 */
public class VersionActivity extends FragmentActivity implements View.OnClickListener{

    private TextView mTextViewVersion;
    private int mVersioncode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_version_layout);
        initView();
    }

    private void initView() {
        mTextViewVersion = (TextView) findViewById(R.id.tv_version);
        findViewById(R.id.btn_back).setOnClickListener(this);
        getVersionInfo();
    }

    private void getVersionInfo() {
        PackageInfo pi = null;
        try {
            PackageManager pm = this.getPackageManager();
            pi = pm.getPackageInfo(this.getPackageName(), 0);
            mVersioncode = pi.versionCode;
            mTextViewVersion.setText("v" + String.valueOf(mVersioncode) + ".0");
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onClick(View v) {
        if(v == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.btn_back:
                finish();
                break;
        }
    }
}
